﻿using CLM.Gestao.Interfaces;
using System.Linq;

namespace CLM.Gestao.Administrador.DAL
{
    public class IndicadorDespesaDAO<T> : IDAO<T> where T : TB_INDICADOR_DESPESA
    {
        PlanejamentoBIRDSEntities model = new PlanejamentoBIRDSEntities();

        public void Add(T pEntity)
        {
            model.TB_INDICADOR_DESPESA.AddObject(pEntity);
        }

        public T Save(T pEntity)
        {
            model.SaveChanges();
            return pEntity;
        }

        public void Delete(T pEntity)
        {
            model.TB_INDICADOR_DESPESA.Attach(pEntity);
            model.TB_INDICADOR_DESPESA.DeleteObject(pEntity);
        }

        public void Update(T pEntity)
        {
            model.TB_INDICADOR_DESPESA.Attach(pEntity);
            model.ObjectStateManager.
              ChangeObjectState
              (pEntity, System.Data.EntityState.Modified);
        }

        public IQueryable<T> GetAll()
        {
            model = new PlanejamentoBIRDSEntities();
            return model.CreateObjectSet<T>();
        }
    }
}